package com.group.service;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.group.dao.TickerDao;

@Service
public class CasinoService {
	protected SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");

	@Autowired
	TickerDao tickerDao;

	/**
	 * 判断是否有红包机会
	 * 
	 * @param userId
	 * @return
	 */
	public boolean hasRedPack(Long userId) {
		// 从来没有红包的人有一次机会
		int count = tickerDao.countUserRedpack(userId);
		if (count == 0)
			return true;

		String date = df.format(new Date());
		double betCount = tickerDao.countTodayBet(userId, date);
		int reCount = tickerDao.countTodayRedpack(userId, date);

		// 当天下注超过300 并且没发过红包
		if (betCount >= 300 && reCount == 0)
			return true;

		return false;
	}

}
